package com.zc58s.config;

import com.zc58s.filter.MyFilter;
import com.zc58s.interceptor.MyInterceptor;
import com.zc58s.servlet.MyServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 *
 * @author : fujc-dev@qq.com
 * @created : 2022/10/14 13:11
 */
@Configuration
//@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
    @Autowired
    private MyInterceptor interceptor;

    /**
     * 注册拦截器 * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor).addPathPatterns("/**").excludePathPatterns("/index.html", "/");
    }

    /**
     * 注册一个filter * @return
     */
    @Bean
    public FilterRegistrationBean tulingFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new MyFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        return filterRegistrationBean;
    }

    //@Bean
    public ServletRegistrationBean tulingServlet() {
        return new ServletRegistrationBean(new MyServlet());
    }
}
